# @Author ZhangGJ
# @Date 2021/11/22 15:16

import cv2.cv2 as cv2


def spilt_bgr():
    bgr_image = cv2.imread('../images/flower.jpg')
    cv2.imshow('2.1', bgr_image)
    b, g, r = cv2.split(bgr_image)
    cv2.imshow('B', b)
    cv2.imshow('G', g)
    cv2.imshow('R', r)
    cv2.waitKey()
    cv2.destroyAllWindows()


def spilt_hsv():
    bgr_image = cv2.imread('../images/flower.jpg')
    cv2.imshow('2.1', bgr_image)
    hsv_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2HSV)
    h, s, v = cv2.split(hsv_image)
    cv2.imshow('H', h)
    cv2.imshow('S', s)
    cv2.imshow('V', v)
    cv2.waitKey()
    cv2.destroyAllWindows()


def merge_rgb():
    bgr_image = cv2.imread('../images/flower.jpg')
    cv2.imshow('2.1', bgr_image)
    b, g, r = cv2.split(bgr_image)
    rbg = cv2.merge([b, g, r])
    cv2.imshow('BGR', rbg)
    rgb = cv2.merge([r, b, g])
    cv2.imshow('RGB', rgb)
    cv2.waitKey()
    cv2.destroyAllWindows()


def merge_hsv():
    bgr_image = cv2.imread('../images/flower.jpg')
    hsv_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2HSV)
    h, s, v = cv2.split(hsv_image)
    hsv = cv2.merge([h, s, v])
    cv2.imshow('HSV', hsv)
    cv2.waitKey()
    cv2.destroyAllWindows()


def split_merge():
    rgb_image = cv2.imread('../images/flower.jpg')
    cv2.imshow('2.1', rgb_image)
    hsv_image = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2HSV)
    h, s, v = cv2.split(hsv_image)
    # h[:, :] = 180
    v[:, :] = 255
    hsv = cv2.merge([h, s, v])
    new_image = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)
    cv2.imshow('NEW', new_image)
    cv2.waitKey()
    cv2.destroyAllWindows()


def alpha():
    bgr_image = cv2.imread('../images/flower.jpg')
    cv2.imshow('2.1', bgr_image)
    bgra_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2BGRA)
    cv2.imshow('BGRA', bgr_image)
    r, g, b, a = cv2.split(bgra_image)
    a[:, :] = 172
    bgra_172 = cv2.merge([r, g, b, a])
    a[:, :] = 0
    bgra_0 = cv2.merge([r, g, b, a])
    # cv2.imshow('A = 172', bgra_172)
    # cv2.imshow('A = 0', bgra_0)
    # cv2.waitKey()
    # cv2.destroyAllWindows()
    cv2.imwrite('../images/save/bgra_iamge.png', bgra_image)
    cv2.imwrite('../images/save/bgra_172.png', bgra_172)
    cv2.imwrite('../images/save/bgra_0.png', bgra_0)


if __name__ == '__main__':
    alpha()
